import pymysql.cursors

connect = pymysql.Connect(
    host='localhost',
    port=3306,
    user='root',
    password='222',
    db='plane',
    charset='utf8'
)
cursor = connect.cursor()


def login():
    _username='zsy'
    _password='222222'
    username = input('输入用户名:')
    password = input('输入密码:')
    print(username,password)
    if username==_username and password==password:
        print("欢迎进入航班订单管理系统")
    else:
        print("用户名或密码错误")


def look():
    print('---------------------------------------------航班订单信息---------------------------------------------')
    sql = "SELECT*from ticket"
    data = ()
    cursor.execute(sql % data)
    for row in cursor.fetchall():
       print("机票编号：%s\t航班号：%s\t出发地：%s\t目的地：%s\t起飞时间：%s\t到达时间：%s\t票价：%s\t舱位类型：%s\t" % row)



def change():
    a=input("请输入机票编号：")
    b=input("请输入您要修改的票价")
    sql="update ticket set pay= '%s' where ticketnumber='%s'"
    data=(b,a)
    cursor.execute(sql%data)
    connect.commit()
    print("修改成功")



def delete():
    a=int(input('请输入要删除的机票编号：'))
    sql="delete from ticket where Ticketnumber='%s'"
    data=(a,)
    cursor.execute(sql%data)
    connect.commit()
    print("成功删除",cursor.rowcount,"条信息")

def add():
    a=input("请输入机票编号：")
    b=input("请输入航班号：")
    c=input("请输入出发地：")
    d=input("请输入目的地：")
    e=input("请输入起飞时间：")
    f=input("请输入到达时间：")
    g=input("请输入票价:")
    h=input("请输入舱位类型：")
    sql="insert into ticket(Ticketnumber,Planenumber,Departure,Destination,takeofftime,arrive,pay,style) " \
        "VALUES (%s,%s,%s,%s,%s,%s,%s,%s)"
    data1=(a,b,c,d,e,f,g,h)
    cursor.execute(sql%data1)
    connect.commit()
    print("添加成功")

while 1:
    try:
        LR = int(input('-----1.登录管理系统 2查看机票信息 3.修改机票信息 4.删除机票信息 5.添加机票信息\n'))
        if LR == 1:
            login()
        elif LR == 2:
            look()
        elif LR == 3:
            change()
        elif LR == 4:
            delete()
        elif LR == 5:
            add()
        elif LR == -1:
            break
        else:
            print('请检查输入信息')
    except:
        print()

